<?php
/**
 * Created by leiying
 * Date: 2017/8/30
 * Time: 17:44
 */
//首页

include_once(GZ_PATH . '/includes/home_func.php');
class homeAction extends Action
{

    /**
     * 首页 -*救助主键
     * @author 
     */
    public function my_home(){
        GZ_Api::authToken();
        $uid = _POST("user_id",0);
        $user=$this->getRow('SELECT * FROM '.$this->table('users').' WHERE user_id='.$uid);
        if(empty($user['height'])|| empty($user['age']) || empty($user['weight']) || empty($user['blood_type'])){
           GZ_API::message("请到个人中心完善个人资料",2);
        }
        if($user['is_validated']!=1){
          GZ_API::message("用户未实名认证",2);
        }
        $sql = "SELECT * FROM ".$GLOBALS['db']->table("rescue_type");
        $res = $GLOBALS['db']->getAll($sql);
        foreach ($res as $k => $v) {
            $res[$k]['logo'] = GZ_Api::get_url($v['logo']);
        }
        GZ_Api::outPut($res);

    }

    //首页救护信息
    public function rescue_info(){
      $sql="SELECT * FROM ".$this->table('rescue_log')." WHERE status=0 OR status=1 order by add_time desc limit 5";
      $data=$this->getAll($sql);
      $arr=array();
      $res=array();
      foreach ($data as $k => $v) {
         $arr[$k]['user_name']=$this->getOne("select user_name from ".$this->table('users')." WHERE user_id=".$v['user_id']);
         $arr[$k]['rescue_type']=$this->getOne("select name from ".$this->table('rescue_type')." WHERE id=".$v['rescue_type']);
		 $res[$k]['log_id'] = $v['id'];
		 $res[$k]['user_name'] = $arr[$k]['user_name'];
		 $res[$k]['rescue_type'] = $arr[$k]['rescue_type'];
		 $res[$k]['rescue_status'] = $v['status'];
        // $res[$k]['rescue_info']="用户".$arr[$k]['user_name']."发布了".$arr[$k]['rescue_type']."求助,正在等待救援中!";
      }

      GZ_Api::outPut($res);
    }


    public function get_news_info(){
      $news_id = _POST("news_id", 0);
      $get_type = _POST("get_type", '');
      
      $res_info = array();
      if($get_type == 'news_list'){
        
        $sql = "select id,title,intro,s_img_url, addtime from ".
        $this->table("article").' WHERE cid = 1 ORDER BY id DESC';
        $res_info = $this->getAll($sql);
        
      }else{
        
        $sql = 'select title,intro,content,addtime from '.$this->table("article").
        ' WHERE cid = 1 AND id='.$news_id.' LIMIT 1';
        $res_info = $this->getRow($sql);
        
        if($res_info){
          $res_info['addtime'] = date('Y-m-d h:i',$res_info['addtime']);
        }
    }
    
    GZ_Api::outPut($res_info);
  }



}
